﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TrackSystem.Entities.RequestFeature
{
    /// <summary>
    /// 分页参数
    /// </summary>
    public class PageParameter
    {
        /// <summary>
        /// 总行数
        /// </summary>
        public int TotalCount { get; set; }
        /// <summary>
        /// 每页项目数
        /// </summary>
        public int PageSize { get; set; }
        /// <summary>
        /// 当前页面号 从1开始
        /// </summary>
        public int CurrentPage { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }
        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNext { get; set; }
        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPrevious { get; set; }
        /// <summary>
        /// 过滤字符串
        /// </summary>
        public string? Filter { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        public PageParameter(int totalCount = 1, int pageSize = 10, int currentPage = 1)
        {
            TotalCount = totalCount;
            PageSize = pageSize;
            CurrentPage = currentPage;
            TotalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
            HasNext = (currentPage < TotalPages);
            HasPrevious = (currentPage > 1);
            Filter = string.Empty;
        }
    }
}
